﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FITClub.Util;
using Microsoft.Xna.Framework;

namespace FITClub.TextureMenu.Configuration
{
    public class ColorEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            if (context.PropertyDescriptor.PropertyType == typeof(Color))
            {
                using (ColorDialog colorDialog = new ColorDialog())
                {
                    colorDialog.AllowFullOpen = true;
                    colorDialog.AnyColor = true;
                    colorDialog.Color = ((Color)value).ToFormsColor();
                    if (colorDialog.ShowDialog() == DialogResult.OK)
                    {
                        return colorDialog.Color.ToXnaColor();
                    }
                }
            }
            return value;
        }
    }
}